package com.doge.controller.admin;

import com.doge.bean.base.BaseData;
import com.doge.bean.base.BaseParam;
import com.doge.bean.base.BaseRespVo;
import com.doge.bean.pojo.admin.Admin;
import com.doge.exception.Delete502Exception;
import com.doge.exception.Param402Exception;
import com.doge.service.admin.admin.AdminService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: doge
 * @description: 管理员管理
 * @author: Keyu Li
 * @create: 2021-11-29 20:19
 **/

@RestController
@RequestMapping("admin/admin")
public class AdminController {

    @Autowired
    AdminService adminService;

    /*
    * get 返回 admin list
    * */
    @RequestMapping("list")
    @RequiresPermissions("admin:admin:list")
    public BaseRespVo list(BaseParam param,String username){
        // 查询得到全部 Base
        BaseData data = adminService.list(param,username);
        // 返回 BaseRespVo
        return BaseRespVo.ok(data);
    }

    @RequestMapping("create")
    @RequiresPermissions("admin:admin:create")
    public BaseRespVo create(@RequestBody Admin admin, HttpServletRequest request) throws Exception {
        // 验证 integer 是否正确接收？ ---> 可以正确接收
        // 将 admin插入到表中，并返回更详细的信息
        adminService.create(admin,request);
        return BaseRespVo.ok(admin);
    }


    @RequestMapping("update")
    @RequiresPermissions("admin:admin:update")
    public BaseRespVo update(@RequestBody Admin admin,HttpServletRequest request) throws Exception {
        adminService.update(admin,request);
        return BaseRespVo.ok(admin);
    }

    @RequestMapping("delete")
    @RequiresPermissions("admin:admin:delete")
    public BaseRespVo delete(@RequestBody Admin admin,HttpServletRequest request) throws Exception {
        adminService.delete(admin,request);
        return BaseRespVo.ok();
    }


}
